﻿using System;
using System.Text;

namespace dotHTML.HTML {
    /// <summary>
    /// Represents a label for a form item.
    /// </summary>
    [Serializable]
    public class Label : Element {
        private Element _for;
        private Form _form;

        /// <summary>
        /// Determines the form item that this label refers to.
        /// </summary>
        public Element For {
            get { return _for; }
            set { _for = value; }
        }

        /// <summary>
        /// Determines the parent form of this label.
        /// </summary>
        public Form Form {
            get { return _form; }
            set { _form = value; }
        }

        /// <summary>
        /// Gets a formatted string of all local attributes of this element
        /// (not including the base attributes).
        /// </summary>
        /// <param name="sb">The StringBuilder to write this element's
        /// attribute data to.</param>
        protected override void WriteLocalAttributes(StringBuilder sb) {
            if (_for != null)  AttributeWriter.Write(sb, _for.ID, "for");
            if(_form != null) AttributeWriter.Write(sb, _form.ID, "form");
        }
    }
}
